﻿<ResourceDictionary
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="clr-namespace:FancyGrid"
   xmlns:dg="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <local:HeaderFilterConverter x:Key="headerConverter"/>

    <Style TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                    <dg:DataGridHeaderBorder x:Name="dataGridHeaderBorder" Margin="0" VerticalAlignment="Top"  IsClickable="{TemplateBinding CanUserSort}" IsHovered="{TemplateBinding IsMouseOver}" IsPressed="{TemplateBinding IsPressed}" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}" SortDirection="{TemplateBinding SortDirection}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" Grid.ColumnSpan="1">
                        <Grid x:Name="grid" Width="Auto" Height="Auto" RenderTransformOrigin="0.5,0.5">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <ContentPresenter x:Name="contentPresenter"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                    ContentStringFormat="{TemplateBinding ContentStringFormat}" 
                                    ContentTemplate="{TemplateBinding ContentTemplate}">
                                <ContentPresenter.Content>
                                    <MultiBinding Converter="{StaticResource headerConverter}">
                                        <MultiBinding.Bindings>
                                            <Binding ElementName="filterTextBox" Path="Text" />
                                            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Content" />
                                        </MultiBinding.Bindings>
                                    </MultiBinding>
                                </ContentPresenter.Content>
                            </ContentPresenter>
                            <TextBox Margin="-5,5,-5,0" x:Name="filterTextBox"  VerticalAlignment="Stretch" 
                                     HorizontalAlignment="Stretch" OpacityMask="Black"  Text="" TextWrapping="Wrap"  
                                     Grid.Row="1" MinHeight="25" Background="Cornsilk">
                            </TextBox>
                        </Grid>
                    </dg:DataGridHeaderBorder>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

